﻿namespace FiftyOne.Foundation.Mobile.Detection.Wurfl.Handlers
{
    using FiftyOne.Foundation.Mobile.Detection.Wurfl;
    using System;

    internal class OperaMiniHandler : RegexSegmentHandler
    {
        private const string DEFAULT_DEVICE = "opera_mini_ver1";
        private const byte EXTRA_CONFIDENCE = 1;
        private static readonly string[] PATTERNS = new string[] { @"(?<=Opera Mini/)\d.\d", @"(?<=Opera/)[\d.]+" };
        private static readonly string[] SUPPORTED_ROOT_DEVICES = new string[] { "opera_mini_ver1" };

        public OperaMiniHandler() : base(PATTERNS, new int[] { 1, 1 })
        {
            base._firstMatchOnly = true;
        }

        protected internal override bool CanHandle(string userAgent)
        {
            return (InternalCanHandle(userAgent) && base.CanHandle(userAgent));
        }

        internal static bool InternalCanHandle(string userAgent)
        {
            return userAgent.Contains("Opera Mini");
        }

        internal override byte Confidence
        {
            get
            {
                return (byte) (base.Confidence + 1);
            }
        }

        internal override DeviceInfo DefaultDevice
        {
            get
            {
                DeviceInfo deviceInfoFromID = Provider.Instance.GetDeviceInfoFromID("opera_mini_ver1");
                if (deviceInfoFromID != null)
                {
                    return deviceInfoFromID;
                }
                return base.DefaultDevice;
            }
        }

        protected override string[] SupportedRootDeviceIds
        {
            get
            {
                return SUPPORTED_ROOT_DEVICES;
            }
        }
    }
}

